package com.njwb.day12;

import java.lang.reflect.*;

// 接口
interface Service {
    void doSomething();
}

// 目标类
class RealService implements Service {
    public void doSomething() {
        System.out.println("执行核心业务");
    }
}

// 代理处理器
class MyInvocationHandler implements InvocationHandler {
    private Object target;

    public MyInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("前置逻辑");
        Object result = method.invoke(target, args); // 调用目标方法
        System.out.println("后置逻辑");
        return result;
    }
}
